
import 'package:dk_flutter_module_sale/phoenix/home/bean/home_contract_bean.dart';
import 'package:flutter/material.dart';
import '../bean/ui_const_bean.dart';
import 'contract_item_widget.dart';

class ContractSectionWidget extends StatelessWidget {

  final ContractBean   contractBean;
  ContractSectionWidget(this.contractBean);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      color: Colors.white,
      height: UIConstBean.ContractSectionH,
      child:  _buildStatusLine(),
    );
  }

  Widget _buildStatusLine() {
    return Column(
      mainAxisAlignment: MainAxisAlignment.start,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        SizedBox(height: 18,),
        Text(contractBean!= null? contractBean.title : '',
          textAlign: TextAlign.left,
          style: TextStyle(color: Color(0xff666666), fontSize: 14,),
        ),
        SizedBox(height: 16,),
        _buildDetainStatusLine(),
      ],
    );
  }

  Widget _buildDetainStatusLine() {
    return Container(
      height: UIConstBean.ContractItemH,
      width: double.infinity,
      color: Colors.white,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: getWidgets(),
      ),
    );
  }

  List<Widget> getWidgets() {
    List<Widget> results = List<Widget>();
    results.add(Spacer());
    if(contractBean!= null) {
      if(contractBean.items.length == 1) {
        results.add(ContractItemWidget(contractBean.items[0], false, false));
      } else {
        int len = contractBean.items.length;
        for(int i = 0;i < len; i++) {
          results.add(ContractItemWidget(contractBean.items[i],(i!= len -1)? true : false ,len > 4 ? true : false ));
        }
      }
    } else {
      List<String> titles = ['待签约','待支付','待签署','完成'];
      for (int i = 0; i < 4; i++ ) {
        ContractItemBean itemBean = ContractItemBean(stateName: titles[i],state: 2);
        results.add(ContractItemWidget(itemBean, i < 3 ? true : false ,false ));
      }
    }
    results.add(Spacer());
    return results;
  }
}